package org.dromara.web.service

import org.dromara.common.core.exception.ServiceException
import org.dromara.common.core.utils.SpringUtils
import org.dromara.system.domain.vo.SysClientVo
import org.dromara.web.domain.vo.LoginVo

/**
 * 授权策略
 *@author LikeYouDo
 *@date 2025/1/3 14:16
 */
interface IAuthStrategy {
    companion object {
        const val BASE_NAME = "AuthStrategy"

        /**
         * 登录
         *
         * @param body      登录对象
         * @param client    授权管理视图对象
         * @param grantType 授权类型
         * @return 登录验证信息
         */
        @JvmStatic
        fun login(body: String, client: SysClientVo, grantType: String?): LoginVo {
            // 授权类型和客户端id
            val beanName = grantType + BASE_NAME
            if (!SpringUtils.containsBean(beanName)) {
                throw ServiceException("授权类型不正确!")
            }
            val instance = SpringUtils.getBean<IAuthStrategy>(beanName)
            return instance.login(body, client)
        }
    }

    /**
     * 登录
     *
     * @param body   登录对象
     * @param client 授权管理视图对象
     * @return 登录验证信息
     */
    fun login(body: String, client: SysClientVo): LoginVo
}
